/**
 *  pipe.h - Related routines and structs of pipe.
 *
 *  Copyright (C) 2008-2009 ZhangHu
 *  All rights reserved.
 *  E-MAIL: anmnmnly@gmail.com
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */


#ifndef __PIPE_H__
#define __PIPE_H__

#include "include/types.h"

#ifndef UNIT_DEBUG
#include "include/mem.h"
#include "include/irq.h"
#include "include/core.h"
#endif


typedef struct pipe {
    word_t send_id;     /* ID of task that sends data to pipe */
    word_t rev_id;      /* ID of task that receives data from pipe */
    uword_t size;       /* The size of pipe */
    uword_t used;       /* The number of used space of pipe */
    void **start;       /* Pointer to the start address of pipe */
    void **end;         /* Pointer to the end address of pipe */
    void **in;          /* Pointer to the write position of pipe */
    void **out;         /* Pointer to the read position pipe */
} pipe_t;

/* pipeInit - It creates a new pipe */
pipe_t *pipeInit(word_t SendID, /* ID of sending task */
                 word_t RevID,  /* ID of receiving task */
                 uword_t Size);  /* The size of pipe */

/* pipeSend - Sending a message to a pipe */
bool_t pipeSend(pipe_t *pPipe,  /* Pointer to the pipe */
                 void *pMsg);    /* Pointer to the message */

void *pipeRev(pipe_t *pPipe);     /* Pointer to the pipe */

/* Get current used space of pipe. */
word_t pipeGetUsed(const pipe_t *pPipe);

/* Clear a pipe */
void pipeClear(pipe_t *pPipe);

/* Delete a pipe */
void pipeDel(pipe_t *pPipe);

#endif

